// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
function setAlarm(event) {
  const minutes = parseFloat(event.target.value);
  chrome.action.setBadgeText({ text: "ON" });
  chrome.alarms.create({ delayInMinutes: 0.5 });
  chrome.storage.sync.set({ minutes: minutes });
  window.close();
}

function clearAlarm() {
  chrome.action.setBadgeText({ text: "" });
  chrome.alarms.clearAll();
  window.close();
}

// An Alarm delay of less than the minimum 1 minute will fire
// in approximately 1 minute increments if released
document.getElementById("sampleMinute").addEventListener("click", setAlarm);
document.getElementById("min15").addEventListener("click", setAlarm);
document.getElementById("min30").addEventListener("click", setAlarm);
document.getElementById("cancelAlarm").addEventListener("click", clearAlarm);
document.getElementById("cancelTheme").addEventListener("click", () => {
  document.body.style.filter = "unset";
});

chrome.storage.local.get(["contentData"], function (result) {
  if (result.contentData) {
    document.body.style.height = result.contentData.innerHeight + "px";
  }
});
